#!/bin/bash
cd ~/app-root/data/temp/tool/TVLive/
curl https://raw.githubusercontent.com/haiwx/m3u8/master/%E7%94%B5%E8%A7%86%E7%9B%B4%E6%92%AD%E5%88%97%E8%A1%A8%E5%81%A5%E5%BA%B7%E7%89%88.m3u8 -o TVLive2.m3u8
if ! diff -q TVLive2.m3u8 TVLive.m3u8; then
mv -f TVLive2.m3u8 TVLive.m3u8
sed -e '1d' -e 'N;s/\n/,/' TVLive.m3u8 >PotPlayerMini.m3u8
rm -f TVLive.dpl
s=$(sed -n '/$/=' PotPlayerMini.m3u8|sed -n '$p')
for ((i=1;i<=$s;i++)); do
    sed -n "${i}p" PotPlayerMini.m3u8|awk -F ',' '{print "'$i'*file*"$3"\n'$i'*title*"$2"\n'$i'*played*0"}' >> TVLive.dpl
done
sed -i '1i DAUMPLAYLIST\ntopindex=0' TVLive.dpl
rm -f PotPlayerMini.m3u8
mv -f TVLive.dpl $OPENSHIFT_DATA_DIR/list/TVLive.dpl
else
rm -f TVLive2.m3u8
fi
